// 实体ID类型
export type UUID = string;

// 枚举类型
export enum TelemetryType {
  UMA = 'UMA',
  UKM = 'UKM',
}

export enum AnalysisStatus {
  NOT_ANALYZED = 'NOT_ANALYZED',
  ANALYZED = 'ANALYZED',
  NOT_NEEDED = 'NOT_NEEDED',
  NEEDS_COLLECTION = 'NEEDS_COLLECTION',
}

export enum TeamRole {
  PL = 'PL', // 产品负责人
  SE = 'SE', // 软件工程师
  MDE = 'MDE', // 机器学习工程师
  ANALYST = 'ANALYST', // 数据分析师
  VIEWER = 'VIEWER', // 查看者
}

export enum ExtractionStatus {
  PENDING = 'PENDING',
  RUNNING = 'RUNNING',
  COMPLETED = 'COMPLETED',
  FAILED = 'FAILED',
}

// 基础实体接口
export interface BaseEntity {
  id: UUID;
  createdAt: string;
  updatedAt?: string;
  isActive: boolean;
}

// 组织
export interface Organization extends BaseEntity {
  name: string;
  description?: string;
}

// 用户
export interface User extends BaseEntity {
  email: string;
  name: string;
}

// 团队
export interface Team extends BaseEntity {
  organizationId: UUID;
  name: string;
  description?: string;
  businessScope?: string;
  contactLead?: string;
  contactEmail?: string;
  memberCount?: number;
  members?: TeamMembership[];
}

// 团队角色
export interface TeamRoleDefinition {
  id: UUID;
  roleCode: TeamRole;
  roleName: string;
  description: string;
  isActive: boolean;
}

// 团队成员关系
export interface TeamMembership extends BaseEntity {
  userId: UUID;
  teamId: UUID;
  roleId: UUID;
  startedAt: string;
  endedAt?: string;
  user?: User;
  role?: TeamRoleDefinition;
}

// 遥测点
export interface TelemetryPoint extends BaseEntity {
  name: string;
  description?: string;
  telemetryType: TelemetryType;
  sourceFile?: string;
  sourceLine?: number;
  chromiumPath?: string;
  ownerInChromium?: string;
  metadata?: Record<string, any>;
  analysisStatus: AnalysisStatus;
  analysisNotes?: string;
  analysisCompletedAt?: string;
  analysisCompletedBy?: UUID;
  discoveredAt: string;
}

// 遥测所有权
export interface TelemetryOwnership extends BaseEntity {
  telemetryPointId: UUID;
  teamId: UUID;
  assignedAt: string;
  assignedBy?: UUID;
  assignmentReason?: string;
  team?: Team;
}

// 业务场景
export interface BusinessScenario extends BaseEntity {
  telemetryPointId: UUID;
  title: string;
  description: string;
  useCase?: string;
  expectedInsights?: string;
  createdBy?: UUID;
}

// 拒绝原因
export interface RejectionReason extends BaseEntity {
  telemetryPointId: UUID;
  reasonCategory: string;
  reasonDescription: string;
  alternativeApproach?: string;
  createdBy?: UUID;
}

// 提取运行
export interface ExtractionRun extends BaseEntity {
  runId: UUID; // 任务ID，与id相同但为了兼容性保留
  chromiumPath: string;
  status: ExtractionStatus;
  progressPercentage: number;
  totalFilesProcessed: number;
  processedFiles?: number; // 已处理文件数
  totalFiles?: number; // 总文件数
  foundPoints?: number; // 发现的点数
  totalPointsFound: number;
  newPointsFound?: number;
  updatedPoints?: number;
  errorMessage?: string;
  errorDetails?: Record<string, any>;
  startedAt?: string | Date;
  completedAt?: string | Date;
  createdBy?: UUID;
  extractionConfig?: Record<string, any>; // 提取配置
}

// 活动日志
export interface ActivityLog {
  id: UUID;
  activityType: string;
  telemetryPointId?: UUID;
  teamId?: UUID;
  userId?: UUID;
  description: string;
  oldValues?: Record<string, any>;
  newValues?: Record<string, any>;
  metadata?: Record<string, any>;
  createdAt: string;
}

// 仪表板数据
export interface TeamDashboardData {
  team: Team;
  progressSummary: {
    totalOwnedPoints: number;
    analyzedPoints: number;
    notAnalyzedPoints: number;
    needsCollectionPoints: number;
    notNeededPoints: number;
    analysisCompletionRate: number;
  };
  recentActivity: ActivityLog[];
}